<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>类别设置</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<script type="text/javascript" src="<%=path %>/js/jquery.js"></script>
	<script type="text/javascript" src="<%=path %>/js/data.js"></script>
	<script type="text/javascript" src="<%=path %>/js/ToastMessage.js"></script>
	<script type="text/javascript" src="<%=path %>/plugin/js/colorpicker.js"></script>
	<style type="text/css">
		table,td,tr,th {
		border:1px solid #cccccc;
		border-collapse:collapse;
		} 
		.dataTable{
			margin-left:20px;
			margin-top:20px;
			font-size:14px;
		}
		th {
			padding:8px;
		}
		#name {
			margin-left:20px;
			margin-top:20px;
		}
		td {
			padding-left:5px;
			padding-right:5px;
		}
		a {
			margin:5px;
		}
	</style>

  </head>
  
  <body>
  	<form action="<%=path%>/system/dataType/save.v" method="post" id="form">
  	名称:<input type="text" name="dataType.name" id="name"><input type="button" value="保存" id="save"><input type="button" value="更新" id="update"><input type="button" value="刷新" id="refresh">
    <table class="dataTable">
    		<tr>
    			<th>序号</th>
    			<th>名称</th>
    			<th>操作</th>
    		</tr>
    		<s:iterator id="dataType" value="dataTypeList">
    				<tr id='<s:property value="#dataType.id"/>'>
    						<td><s:property value="#dataType.id"/> </td>
    						<td><s:property value="#dataType.name"/></td>
    						<td><a href="javascript:void(0);">修改</a><a href="javascript:void(0);">删除</a></td>
    				</tr>
    		</s:iterator>
    </table>
    <input type="hidden" name="dataType.id" id="dataTypeId"> 
    </form>
    <script type="text/javascript">
    	$(document).ready(function(){
					$("#save").bind("click",function(){
								if($("#name").val()==""){
											alert("请输入名称");
											return;
									}
								$("#dataTypeId").val("");
								$("#form").submit();
					});
					$("#update").bind("click",function(){
						if($("#name").val()==""){
									alert("请输入名称");
									return;
							}
						if($("#dataTypeId").val()==""){
								alert("不能更新，请点击保存");
								return;
							}
						if(confirm("是否更新该数据??")){
							$("#form").attr("action","<%=path%>/system/dataType/update.v")
							$("#form").submit();
						}
			});
					$("#refresh").bind("click",function(){
						$("#form").attr("action","<%=path%>/system/dataType/list.v");
						$("#form").submit();
						});
						$("tr").each(function(){
									var id = $(this).attr("id");
									var $this = $(this);
									//删除
									$(this).find("a").eq(1).bind("click",function(){
										if(confirm("是否删除该数据，谨慎操作")){
											$("#dataTypeId").val(id);
											$("#form").attr("action","<%=path%>/system/dataType/delete.v");
											$("#form").submit();
										}
									});
									//修改
									$(this).find("a").eq(0).bind("click",function(){
										$("#dataTypeId").val(id);
										$("#name").val($this.find("td").eq(1).text());
								});
						})
       });
    
    
    </script>
  </body>
</html>
